﻿using Wechat_PublicNumber.Common;

namespace Wechat_PublicNumber.Jobs.SustainJobs
{
    [Injection(DIPattern.Singleton, InitMethod = nameof(Run))]
    public class StockMonitorJob
    {
        [Autowired]
        private CommonHttpInvoke _commonHttpInvoke;

        private async Task Run()
        {
            var xx = await _commonHttpInvoke.GetRealTimeStock("SH000001");

            var xzcafda = 11111;

            //var xx = _commonHttpInvoke.GetRealTimeStock("SH000001").Result;
            //decimal currentPercent = 0;
            //List<decimal> percentList = new List<decimal>();

            //while (true)
            //{
            //    var huA = _commonHttpInvoke.GetRealTimeStock("SH000001").Result;

            //    percentList.Add(huA.CurrentPercent - currentPercent);

            //    var totalPercent = percentList.Sum();
            //}


            //int upcontinuity = 0;
            //int downcontinuity = 0;
            ////decimal currentPercent = 0;

            //while (true)
            //{
            //    var huA = _commonHttpInvoke.GetRealTimeStock("SH000001").Result;

            //    if (huA.CurrentPercent != currentPercent && currentPercent != 0)
            //    {
            //        if (huA.CurrentPercent > currentPercent)
            //            upcontinuity++;
            //        else if (huA.CurrentPercent < currentPercent)
            //            downcontinuity++;
            //        else
            //        {
            //            if (huA.CurrentPercent - currentPercent > 0.02m)
            //                upcontinuity = 0;
            //            else if (currentPercent - huA.CurrentPercent > 0.02m)
            //                downcontinuity = 0;
            //        }
            //    }

            //    currentPercent = huA.CurrentPercent;

            //    if (upcontinuity == 5)
            //    {
            //        Console.WriteLine();
            //        Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} up");
            //        upcontinuity = 0;
            //    }

            //    if (downcontinuity == 5)
            //    {
            //        Console.WriteLine();
            //        Console.WriteLine($"{DateTime.Now:yyyy-MM-dd HH:mm:ss} down");
            //        downcontinuity = 0;
            //    }

            //    Task.Delay(6000).Wait();
            //}
        }
    }
}
